package me.ingxin.android.sample.lego.handler

import android.content.Context
import android.util.Log
import android.widget.Toast
import me.ingxin.android.router.annotaions.Route
import me.ingxin.android.router.route.Request
import me.ingxin.android.router.route.Result
import me.ingxin.android.router.route.RouteHandler
import me.ingxin.android.sample.lego.interceptor.Global4Interceptor

/**
 * Created by ingxin on 2022/4/27
 */
@Route("/handler/test4", interceptorName = ["test4"], interceptor = [Global4Interceptor::class])
class Test4Handler : RouteHandler() {
    override fun handle(context: Context, request: Request) {
        val a = request.getInt("a")
        val b = request.getInt("b")
        Toast.makeText(context, "Test1Handler：计算$a+$b=?", Toast.LENGTH_SHORT).show()

        //设置结果回传
        setResult(Result(Result.SUCCEED).apply {
            putInt("res", a + b)
        })
    }

    override fun onRelease() {
        Log.d("Lego:Router", "释放Test4Handler")
    }

}